package com.lzx.mumianaicodegenerator.core.saver;

import cn.hutool.core.util.StrUtil;
import com.lzx.mumianaicodegenerator.ai.model.enums.CodeGenTypeEnum;
import com.lzx.mumianaicodegenerator.ai.model.MultiFileCodeResult;
import com.lzx.mumianaicodegenerator.exception.BusinessException;
import com.lzx.mumianaicodegenerator.exception.ErrorCode;

public class MultiFileCodeFileSaverTemplate extends CodeFileSaverTemplate<MultiFileCodeResult>{
    @Override
    protected CodeGenTypeEnum getCodeType() {
        return CodeGenTypeEnum.MULTI_FILE;
    }

    @Override
    protected void saveFiles(MultiFileCodeResult result, String baseDirPath) {
        writeToFile(baseDirPath,"index.html",result.getHtmlCode());
        writeToFile(baseDirPath,"style.css",result.getCssCode());
        writeToFile(baseDirPath,"script.js",result.getJsCode());
    }
    @Override
    protected void validateInput(MultiFileCodeResult result){
        super.validateInput(result);
        if (StrUtil.isBlank(result.getHtmlCode()))
            throw new BusinessException(ErrorCode.SYSTEM_ERROR, "保存文件失败，htmlCode为空");
    }
}
